-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Computing full effective mappings for data stream mapping APIs #130498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Computing full effective mappings for data stream mapping APIs #130498
Conversation
Pinging @elastic/es-data-management (Team:Data Management) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a bug where data stream effective mappings did not include component templates, and unifies mapping computation logic across the get and update data stream mappings APIs.
- Introduces a new
getEffectiveMappings
overload that merges composable and component template mappings viaIndicesService
. - Updates services and transport actions to pass
IndicesService
into mapping computation. - Exposes helper methods in
ComposableIndexTemplate
and adjusts tests and YAML fixtures to validate the merged mappings.
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
server/src/main/java/.../DataStream.java | Adds overloaded getEffectiveMappings with full merge logic. |
server/src/main/java/.../MetadataDataStreamsService.java | Switches to new mapping logic for update APIs. |
server/src/main/java/.../MetadataCreateIndexService.java | Refines collectV2Mappings exception signatures. |
server/src/main/java/.../ComposableIndexTemplate.java | Makes merge and conversion helpers public. |
modules/data-streams/.../TransportUpdateDataStreamMappingsAction.java | Injects IndicesService and uses new API. |
modules/data-streams/.../TransportGetDataStreamMappingsAction.java | Injects IndicesService and uses new API. |
server/.../DataStreamTests.java | Updates test to call new getEffectiveMappings signature. |
modules/data-streams/.../250_data_stream_mappings.yml | Adjusts YAML expectations for merged mappings. |
modules/data-streams/.../TransportUpdateDataStreamMappingsActionIT.java | Updates IT to include timestamp and component fields. |
modules/data-streams/.../DataStreamIT.java | Adds end-to-end test for new effective mappings logic. |
Comments suppressed due to low confidence (3)
modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/DataStreamIT.java:2555
- [nitpick] Instantiating a new
ActionType
here bypasses the existingUpdateDataStreamMappingsAction.INSTANCE
. For consistency and to avoid duplicate registrations, use the providedINSTANCE
constant.
new ActionType<UpdateDataStreamMappingsAction.Response>(UpdateDataStreamMappingsAction.NAME),
server/src/main/java/org/elasticsearch/cluster/metadata/DataStream.java:456
- The call to
collectV2Mappings
uses five arguments, but no such overload exists inMetadataCreateIndexService
. This will fail to compile. Consider invoking the correct helper for merging component mappings, or add a matching overload.
final List<CompressedXContent> mappings = collectV2Mappings(
server/src/test/java/org/elasticsearch/cluster/metadata/DataStreamTests.java:2692
- The test uses
mock(...)
but doesn't import Mockito’smock
method. Addimport static org.mockito.Mockito.mock;
(or a qualifiedMockito.mock
) to avoid compilation errors.
IndicesService indicesService = mock(IndicesService.class);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM from a code cleanliness perspective but I would be more comfortable if this gets a second thumb from someone more familiar with templates and rollover
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I left a couple of questions.
Map<String, Object> originalMappingMap = XContentHelper.convertToMap( | ||
documentMapper.mappingSource().uncompressed(), | ||
true, | ||
XContentType.JSON | ||
).v2(); | ||
if (originalMappingMap.containsKey(MapperService.SINGLE_MAPPING_NAME)) { | ||
resultMapping = (Map<String, ?>) originalMappingMap.get(MapperService.SINGLE_MAPPING_NAME); | ||
} else { | ||
resultMapping = originalMappingMap; | ||
} | ||
return convertMappingMapToXContent(resultMapping); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems a little strange that we uncompress the xcontent, convert it to a map, potentially strip the mapping name, then reconvert it to a compressed xcontent. Should we instead leave the mapping name so that we don't have to do the extra conversions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just trying to avoid sometimes having _doc
in the effective mappings for the sake of consistency. I can remove this part if you think it's overkill.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we do the check, does the default (let's say "undeprecated") version match the originalMappingMap.containsKey(MapperService.SINGLE_MAPPING_NAME)
condition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the question. The default is _doc
, which is MapperService.SINGLE_MAPPING_NAME
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, what I meant is, in the current world, is the default to have _doc
in the mapping, or is it elided by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we usually just deal with it if it exists. It seems confusing as a user (given that most users are probably unaware that we used to allow multiples since that has been gone for quite a while). I had just been trying to make it simpler for users of a new API so that they didn't have to write client code that can handle the result two different ways.
dataStream.getEffectiveMappings(projectMetadata), | ||
indicesService | ||
); | ||
MetadataIndexTemplateService.validateTemplate(mergedEffectiveSettings, null, indicesService); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elaborate on why we don't want to use the effective mappings for validation here? We don't currently, but in the future we could have settings that affect mappings, so we may still want to validate for that here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thinking was that it didn't affect any of the settings we're allowing, so why do the now-more-expensive operation to get effective mappings? I can put it back though -- the mapping-merging wound up being faster than I expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd be best to put it back just so we don't accidentally miss it some time in the future.
IndicesService indicesService = mock(IndicesService.class); | ||
assertThrows(IllegalArgumentException.class, () -> dataStream.getEffectiveMappings(projectMetadataBuilder.build(), indicesService)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the mock, or can we just pass null
in for the service here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh you're right. I'll change that.
The update data stream mappings API (#130241) validates that the effective mapping after applying the user's mapping overrides is still a valid template. However, the effective mapping is generated using only the mapping overrides and the composable template's top-level mapping. It ignores any mappings provided by component templates within the composable template. This is a bug. This PR fixes that bug, and also uses the same new logic for generating the effective_mappings that are returned to the user in the get and update data stream mappings APIs.